/**
 * 
 */
package com.ms.game.itembox.container;

import java.util.ArrayList;

import com.ms.game.itembox.Item;

/**
 * 道具數據基礎
 * 
 * @author TW15010
 */
public abstract class ItemBasic extends UseItemInterface {
	/** 道具id */
	private String itemId;
	
	/** 預設的道具ID*/
	private String defaultItemId;

	/** 給分析server使用時，是否要用default Id*/
	private boolean analysisUseDefaultId;
	
	/** 道具的class名稱*/
	private String itemClassName;

	/** 名稱 */
	private String defaultName;
	
	/** 是否開放*/
	private boolean open;

	/** 可不可以交易*/
	private boolean canTrade;
	
	/** 是否需要目標 */
	private boolean needTarget;

	/** 是否可堆疊 */
	private boolean stackable;

	/** 此道具是否可以精煉 */
	private boolean canRefine;
	
	/** 道具基本精煉等級 */
	private int itemRefineLevel;
	
	/**
	 * 精煉過期時間(小時)<br>
	 * 沒有超過時間的道具不能交易<br>
	 * 超過時間沒有精煉物品自動消失
	 */
	private int refineExpireTime;
	
	/**
	 * 各精煉等級需要的水晶數量<br>
	 * index 0: 精煉到1級需要的水晶數量<br>
	 * index 1: 精煉到2級需要的水晶數量<br>
	 */
	private ArrayList<Integer> refineCrystalCostList;
	
	/** 是否有過期時間*/
	private boolean hasExpireTime;
	
	/** 過期時間*/
	private int expireTime;
	
	/** 使用等級 */
	private int useLevel;
	
	/** 使用Vip等級*/
	private int useVipLevel;
	
	/** 需要送去DC才可以得到效果 */
	private boolean applyItemToDc;

	public String getName() {
		return defaultName;
	}

	public void setName(String name) {
		this.defaultName = name;
	}

	public boolean isNeedTarget() {
		return needTarget;
	}

	public void setNeedTarget(boolean needTarget) {
		this.needTarget = needTarget;
	}

	@Override
	public String toString() {
		return getName();
	}

	public String getItemId() {
		return itemId;
	}

	public void setItemId(String itemId) {
		this.itemId = itemId;
	}

	public String getDefaultItemId() {
		return defaultItemId;
	}

	public void setDefaultItemId(String defaultItemId) {
		this.defaultItemId = defaultItemId;
	}

	public boolean isAnalysisUseDefaultId() {
		return analysisUseDefaultId;
	}

	public void setAnalysisUseDefaultId(boolean analysisUseDefaultId) {
		this.analysisUseDefaultId = analysisUseDefaultId;
	}

	public String getItemClassName() {
		return itemClassName;
	}

	public void setItemClassName(String itemClassName) {
		this.itemClassName = itemClassName;
	}

	public boolean isOpen() {
		return open;
	}

	public void setOpen(boolean open) {
		this.open = open;
	}

	public boolean isCanTrade() {
		return canTrade;
	}

	public void setCanTrade(boolean canTrade) {
		this.canTrade = canTrade;
	}

	public boolean isStackable() {
		return stackable;
	}

	public void setStackable(boolean stackable) {
		this.stackable = stackable;
	}

	public int getRefineExpireTime() {
		return refineExpireTime;
	}

	public void setRefineExpireTime(int refineExpireTime) {
		this.refineExpireTime = refineExpireTime;
	}

	public ArrayList<Integer> getRefineCrystalCostList() {
		return refineCrystalCostList;
	}

	public void setRefineCrystalCostList(ArrayList<Integer> refineCrystalCostList) {
		this.refineCrystalCostList = refineCrystalCostList;
	}

	public boolean isHasExpireTime() {
		return hasExpireTime;
	}

	public void setHasExpireTime(boolean hasExpireTime) {
		this.hasExpireTime = hasExpireTime;
	}

	public int getExpireTime() {
		return expireTime;
	}

	public void setExpireTime(int expireTime) {
		this.expireTime = expireTime;
	}

	public boolean isCanRefine() {
		return canRefine;
	}

	public void setCanRefine(boolean canRefine) {
		this.canRefine = canRefine;
	}
	
	public int getItemRefineLevel() {
		return itemRefineLevel;
	}

	public void setItemRefineLevel(int itemRefineLevel) {
		this.itemRefineLevel = itemRefineLevel;
	}

	public boolean isApplyItemToDc() {
		return applyItemToDc;
	}

	public void setApplyItemToDc(boolean applyItemToDc) {
		this.applyItemToDc = applyItemToDc;
	}
	
	public int getUseLevel() {
		return useLevel;
	}

	public void setUseLevel(int useLevel) {
		this.useLevel = useLevel;
	}

	public int getUseVipLevel() {
		return useVipLevel;
	}

	public void setUseVipLevel(int useVipLevel) {
		this.useVipLevel = useVipLevel;
	}

	/**
	 * 角色等級是否可以使用道具
	 * @param playerLevel 角色等級
	 * @param playerVipLevel 角色等級
	 * @return
	 */
	public boolean isLevelEnoughToUse(int playerLevel) {
		if (playerLevel <= 0) { // 體驗會員不能使用
			return false;
		}

		if (playerLevel < useLevel) { // 不能使用
			return false;
		}

		return true;
	}
	
	
	/**
	 * 角色VIP是否能使用道具
	 * @param playerVipLevel
	 * @return
	 */
	public boolean isVipEnoughToUse(int playerVipLevel) {
		if (playerVipLevel < useVipLevel) {
			return false;
		}

		return true;
	}

	/** 是否是C幣卡 */
	public boolean isGoldCoinCard() {
		if (this instanceof ItemGoldCoinCard) {
			return true;
		}
		return false;
	}

	/** 是否是水晶卡 */
	public boolean isCrystalCard() {
		if (this instanceof ItemCrystalCard) {
			return true;
		}
		return false;
	}

	/** 是否是機台卡 */
	public boolean isGameCard() {
		if (this instanceof ItemGameCard) {
			return true;
		}
		return false;
	}
	
	/** 是否是全頻卡*/
	public boolean isBroadcastCard() {
		if (this instanceof ItemChannelBroadcastCard) {
			return true;
		}
		return false;
	}

	/** 是否是升級卡 */
	public boolean isLevelUpCard() {
		if (this instanceof ItemLevelUpCard) {
			return true;
		}
		return false;
	}

	/** 是否是寶箱 */
	public boolean isTreasureBox() {
		if (this instanceof ItemTreasureBox) {
			return true;
		}
		return false;
	}

	/** 是否是補償寶箱 */
	public boolean isGiftBox() {
		if (this instanceof ItemGiftBox) {
			return true;
		}
		return false;
	}

	/** 是否是更名卡 */
	public boolean isChangeNameCard() {
		if (this instanceof ItemChangeNameCard) {
			return true;
		}
		return false;
	}
	
	public Item toItemFormat(String sn,ItemExtraSettings extraSettings, int count){
		Item item = new Item();
		item.setCount(count);
		item.setExpireTime(expireTime);
		item.setItemId(itemId);
		item.setBasicItemId(defaultItemId);
		item.setCount(1);
		item.setSn(sn);
		item.setExtraSetting(extraSettings);
		item.setRefineEndTime(refineExpireTime);
		item.setRefineLevel(itemRefineLevel);
		return item;
	}
}
